import 'package:flutter/material.dart' ;
import 'package:flutter_screenutil/flutter_screenutil.dart';

class InputField extends StatefulWidget{

  var txt = "请输入" ;
  var leftIcon = null ;
  var rightIcon = null ;
  var input = false ;
  var onComplate = null ;
  var password = false ;

  InputField({Key key , this.txt , this.leftIcon , this.rightIcon , this.input=false , this.onComplate , this.password}):super(key:key) ;

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _InputField() ;
  }
}

class _InputField extends State<InputField> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Row( 
      children: <Widget>[
        Container(
          width:ScreenUtil().setWidth(18) ,
          height:ScreenUtil().setWidth(18) ,
          margin: EdgeInsets.only(left:ScreenUtil().setWidth(15)),
          child: Image.asset(widget.leftIcon ?? "assets/images/school.png" , fit: BoxFit.fill,),
        ) ,
        Expanded(
          child: Container(
            height:widget.input ? 35 : 18 ,
            padding: EdgeInsets.only(left:ScreenUtil().setWidth(39)),
            child: GestureDetector(
              child:!widget.input ? Text(
                widget.txt ,
                style: TextStyle(
                  fontSize: 16 ,
                  color:Color.fromARGB(255, 121, 132, 155) ,
                  height:1.1
                ),
              ) : TextField(
                style: TextStyle(
                  fontSize: 16 ,
                  color:Color.fromARGB(255, 121, 132, 155) ,
                  height:1.1
                ),
                obscureText: widget.password??false,
                decoration: InputDecoration(
                  border: InputBorder.none,
                  hintText: widget.txt
                ),
                onChanged:(v){
                  if(widget.onComplate != null){
                    widget.onComplate(v);
                  }
                }
              ),
            )
          )
        ) ,
        Visibility(
          visible: widget.rightIcon == null ? false : true,
          child: Container(
            width:ScreenUtil().setWidth(16) ,
            height:ScreenUtil().setWidth(16) ,
            margin: EdgeInsets.only(right:ScreenUtil().setWidth(15)),
            child: Image.asset(widget.rightIcon ?? "assets/images/more.png" , fit: BoxFit.fill,),
          ) ,
        )
      ],
    );
  }
}